from django.shortcuts import render
from django.shortcuts import render,get_object_or_404
from django.http import  HttpResponse,HttpResponseRedirect
from django.template import loader
from django.urls import  reverse
from django.views import  generic
from .models import users
# Create your views here.
def login(request,_login=1):


    return  render(request,'useradmin/Login.html')



def check_user(request):

    name = request.POST['username']
    pwd = request.POST['passwd']
    person = users.objects.filter(username=name,passwd=pwd)
    if person:
        print('match a user')
        response =  HttpResponseRedirect(reverse('polls:index'))
        response.set_cookie('username',name,expires=3600)
        return  response

    else:
        return HttpResponseRedirect(reverse('useradmin:login'))
        #return render(request,'useradmin/Login.html')

def logout(request):
    response =  render(request,'useradmin/Login.html')
    response.delete_cookie('username')
    return response